<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="袋内码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['innercode']" placeholder="请输入袋内码"></a-input>
        </a-form-item>
        <a-form-item label="袋外码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['outercode']" placeholder="请输入袋外码"></a-input>
        </a-form-item>
        <a-form-item label="小程序openid" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['appletopenid']" placeholder="请输入小程序openid"></a-input>
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['note']" placeholder="请输入备注"></a-input>
        </a-form-item>
        <a-form-item label="所属项目" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['project']" placeholder="请输入所属项目"></a-input>
        </a-form-item>
        <a-form-item label="积分数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['integralnumber']" placeholder="请输入积分数" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="渠道" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['channel']" placeholder="请输入渠道"></a-input>
        </a-form-item>
        <a-form-item label="内码或外码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['innerorouter']" placeholder="请输入内码或外码" style="width: 100%"/>
        </a-form-item>

        <a-form-item label="产品" :labelCol="labelCol" :wrapperCol="wrapperCol">
<!--          <select>
            <option>aa</option>
            <option>bb</option>
            <option>cc</option>
          </select>-->
          <select v-decorator="['qrcodeid']" placeholder="select product" style="width: 100%">
            <option value="1">aaa</option>
            <option value="2">abbbaa</option>
          </select>
<!--          <a-input-number v-decorator="['qrcodeid']" placeholder="请选择具体产品" style="width: 100%"/>-->
        </a-form-item>

      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import SelectNode from "ant-design-vue/es/vc-tree-select/src/SelectNode";
  alert('drawer');

  console.log('=============================================');
  console.log('==============    start ...    ==========================');
  console.log('=============================================');

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import {getAction} from "../../../api/manage";

  export default {
    name: "FillintegralrecordModal",
    components: {
      SelectNode
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/org.jeecg.modules.com.pointoperation/fillintegralrecord/add",
          edit: "/org.jeecg.modules.com.pointoperation/fillintegralrecord/edit",
          listProduct: "/qrcodeProductList/listAll"
        }
      }
    },
    created () {
      console.log("create ...");
      getAction(httpurl,formData,method).then((res)=>{
        console.log(res);
      });
    },
    methods: {
      add () {
        console.log('add ..............................');
        console.log('add ..............................');
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'innercode','outercode','appletopenid','note','project','integralnumber','channel','innerorouter','qrcodeid'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'innercode','outercode','appletopenid','note','project','integralnumber','channel','innerorouter','qrcodeid'))
      }

    }
  }

/*  mounted(){
    getAction(httpurl,formData,method).then((res)=>{
      console.log(res);
    });
  }*/

</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>